import axios from "axios";

export default function $axios(options) {
  return new Promise((resolve, reject) => {
    const service = axios.create({
      baseURL: process.env.BASE_API,// src/config目录下的dev和prod两个文件里配置
      method: "get",
      timeout: 10000,
      // 返回数据类型
      responseType: "json"
    });

    // request拦截器
    service.interceptors.request.use(
      config => {
        config.headers["xxx-token"] = 'xiaobusi'; // 让每个请求携带自定义token 这里先写死请根据实际情况自行修改
        config.headers["Content-Type"] = "application/json";
        return config;
      },
      error => {
        // Do something with request error
        console.log(error); // for debug
        Promise.reject(error);
      }
    );
    
    // 请求处理
    service(options)
      .then(res => {
        resolve(res.data);
        return false;
      })
      .catch(error => {
        reject(error);
      });
  });
}
